package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.CheckGroup;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CheckGroupMapper {
    /**
     * 添加检查组
     * @param checkGroup
     */
    @Insert("insert into itcast_health.t_checkgroup (code, name, helpCode, sex, remark, attention) value " +
            "(#{code},#{name},#{helpCode},#{sex},#{remark},#{attention})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void add(CheckGroup checkGroup);

    /**
     * 添加检查组和检查项的关联关系
     * @param checkGroupId
     * @param checkItemId
     */
    @Insert("insert into itcast_health.t_checkgroup_checkitem (checkgroup_id, checkitem_id) value " +
            "(#{checkGroupId},#{checkItemId})")
    void addCheckGroupAndCheckItem(Integer checkGroupId,  int checkItemId);

    /**
     * 根据id删除检查组
     * @param id
     */
    @Delete("delete from itcast_health.t_checkgroup where id = #{id}")
    void deleteById(Integer id);

    /**
     * 根据检查组id查询检查组
     * @param id
     * @return
     */
    @Select("select checkgroup_id from itcast_health.t_setmeal_checkgroup where setmeal_id = #{id}")
    List<Integer> findCheckGroupIdsBySetmealId(Integer id);


    /**
     * 分页查询
     * @param queryString
     * @return
     */

    Page<CheckGroup> findPage(String queryString);

    /**
     * 编辑检查组
     * @param checkGroup
     */
    @Update("update itcast_health.t_checkgroup set code = #{code}, name = #{name}, helpCode = #{helpCode}, sex = #{sex}, remark = #{remark}, attention = #{attention} where id = #{id}")
    Integer edit(CheckGroup checkGroup);

    /**
     * 删除检查组和检查项的关联关系
     * @param id
     */
    @Delete("delete from itcast_health.t_checkgroup_checkitem where checkgroup_id = #{id}")
    void deleteCheckGroupCheckItem(Integer id);

    /**
     * 查询所有检查组
     * @return
     */
    @Select("select * from itcast_health.t_checkgroup")
    List<CheckGroup> findAll();

    /**
     * 根据检查组id查询检查组
     * @param id
     * @return
     */
    @Select("select * from itcast_health.t_checkgroup where id = #{id}")
    CheckGroup findById(Integer id);
}
